<template>
	<div class="content">
		<h2><i class="iconfont icon-jinbi"></i>供应商结算审核列表</h2>
		<div class="content-wrap">
			<!--搜索分类-->
			<div class="search">
				<div class="search__list">
					<div class="search__list--title search__list--title-tip">审核状态</div>
					<el-select v-model="params.is_agree" @change="selctCheckState">
						<el-option label="全部" :value="-1"></el-option>
						<el-option label="未审核" :value="''"></el-option>
						<el-option label="审核通过" :value="1"></el-option>
						<el-option label="审核驳回" :value="0"></el-option>
					</el-select>
				</div>
				<!--<div class="search__list">
					<div class="search__list--title">审核时间</div>
					<el-date-picker
							@change="handleSelectTimes"
						    v-model="times"
						    type="daterange"
						    range-separator="至"
						    start-placeholder="开始日期"
						    end-placeholder="结束日期">
				  	</el-date-picker>
				</div>-->
			</div>
			<!--商品展示表格-->
			<div class="content-table" v-loading="loading" >
				<el-table :data="data" strip height="550" >
					<el-table-column label="供应商名称" align="center">
						<template slot-scope="scope">
							<span>{{scope.row.supplier.supplier_name}}</span>
						</template>
					</el-table-column>
					<el-table-column label="银行卡号" >
						<template slot-scope="scope">
							<span>{{ scope.row.card_no }}</span>
						</template>
					</el-table-column>
					<el-table-column label="申请日期" >
						<template slot-scope="scope">
							<span>{{ scope.row.create_time | formatTime }}</span>
						</template>
					</el-table-column>
					<el-table-column label="审核日期" >
						<template slot-scope="scope">
							<span v-if="scope.row.check_time">{{ scope.row.check_time | formatTime }}</span>
						</template>
					</el-table-column>
					<el-table-column label="审核金额" align="center">
						<template slot-scope="scope">
							<el-tag type="primary" v-if="scope.row.balance_money < 2000">{{scope.row.balance_money}}元</el-tag>
							<el-tag type="danger" v-else>{{scope.row.balance_money}}元</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="状态" align="center">
						<template slot-scope="scope">
							<el-tag type="warning" v-if="scope.row.is_agree === undefined">等待审核</el-tag>
							<el-tag 
								v-else-if="scope.row.is_agree === 0"
								type="danger"
								:title="scope.row.reject_reason ? scope.row.reject_reason : ''"
								>审核驳回</el-tag>
							<el-tag type="success" v-else>审核通过</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="操作" align="center" width="250">
						<template slot-scope="scope" size="small">
							<el-button 
								size="small"
								@click="agreeCheck(scope.row.supplier_balance_id)"
								 type="success" 
								 v-if="scope.row.is_agree === undefined">
								 同意
							</el-button>
							<el-button 
								size="small"
								@click="rejectCheck(scope.row.supplier_balance_id)"
								 type="danger" 
								 v-if="scope.row.is_agree === undefined">
								 拒绝
							</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<el-pagination 
				@current-change="handleCurrentChange"
				background 
				layout="total, prev, pager, next, jumper"
				:total="totalNum" 
				class="fr"
				>
			</el-pagination>
		</div>
	</div>
</template>

<script>
	export default {
		created() {
			this.fetchSupplierCheckList();
		},
		data() {
			return {
				params: {
					page: 1,
					rows: 10,
					is_agree: -1
				},

				data: null,					//提现数据			
				times: "",					//申请日期
				loading: true,				//加载小圈圈
				supplier_balance_id: null,		//申请成为商户用户的id
				totalNum: 0					//返回数据总数，用于分页那里显示
			}
		},
		methods: {
			//翻页
			handleCurrentChange(pages) {
				this.params.page = pages;
				this.fetchSupplierCheckList();
			},
			//选择时间时候触发
			/*handleSelectTimes(val) {
				if (this.times) {
					this.params.start_time = this.times[0].getTime();
					this.params.end_time = this.times[1].getTime();
				}else {
					this.params.start_time = "";
					this.params.end_time = "";
				}
				this.fetchSupplierCheckList();

			},*/
			//选择审核状态0代表未审核，1代表已审核
			selctCheckState(val) {
				this.params.is_agree   = val;
				this.fetchSupplierCheckList();
			},
			//获取供应商结算申请列表
			fetchSupplierCheckList() {
				this.loading = true;
				var url = `${this.url}/supplier/balance_get_list_man.action`;
				var params = this.params;
				this.$http.get(url,{ params }).then((res)=> {
					this.totalNum = res.data.result.total;
					this.loading = false;
					this.data = res.data.result.rows;
				});
			},
			showDetail(id) {
				this.supplier_balance_id = id;
			},
			agreeCheck(id) {
				this.loading = true;
				var url = `${this.url}/supplier/balance_check.action`;
				var params = {
					supplier_balance_id: id,
					is_agree: 1,
					reject_reason: "",
				};
				this.$http.get(url,{ params }).then((res)=> {
					if( res.data.success ) {
						this.fetchSupplierCheckList();
					}else {
						this.$message({
							type: "error",
							message: res.data.result.errmsg
						});
					}
				});
			},
			rejectCheck(id) {
				this.$prompt("请填写拒绝理由", "拒绝申请", {
					cancelButtonText: '取消',
					confirmButtonText: "确定",
				}).then(({ value })=> {
					if (value === null || value.replace(/\s/g, "") === "") {
						this.$message({
							type: "error",
							message: "拒绝失败，理由不能为空"
						});
						return;
					}
					var url = `${this.url}/supplier/balance_check.action`;
					var params = {
						supplier_balance_id: id,
						is_agree: 0,
						reject_reason: value,
					};
					this.$http.get(url,{ params }).then((res)=> {
						this.loading = true;
						if( res.data.success ) {
							this.fetchSupplierCheckList();
						}else {
							this.$message({
								type: "error",
								message: res.data.result.errmsg
							});
						}
					});
				}).catch(()=>{
					
				});
			}
		}

	}
</script>

<style scoped lang="scss">

</style>